package com.irdstudio.efp.cus.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.cus.service.dao.AcctInfoDao;
import com.irdstudio.efp.cus.service.domain.AcctInfo;
import com.irdstudio.efp.cus.service.facade.AcctInfoService;
import com.irdstudio.efp.cus.service.vo.AcctInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Service Impl: 公积金账户信息表服务实现
 *
 * @author gcb
 * @date 2020-08-11
 */
@Service("acctInfoService")
public class AcctInfoServiceImpl implements AcctInfoService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(AcctInfoServiceImpl.class);

    @Autowired
    private AcctInfoDao acctInfoDao;

    /**
     * 新增数据
     *
     * @param acctInfoVo
     * @return
     */
    @Override
    public int insert(AcctInfoVO acctInfoVo) throws Exception {
        AcctInfo acctInfo = new AcctInfo();
        beanCopy(acctInfoVo, acctInfo);
        return acctInfoDao.insert(acctInfo);
    }

    /**
     * 根据主键删除信息
     *
     * @param acctInfoVo
     * @return
     */
    @Override
    public int deleteByPk(AcctInfoVO acctInfoVo) throws Exception {
        AcctInfo acctInfo = new AcctInfo();
        beanCopy(acctInfoVo, acctInfo);
        return acctInfoDao.deleteByPk(acctInfo);
    }

    /**
     * 根据主键更新信息
     *
     * @param acctInfoVo
     * @return
     */
    @Override
    public int updateByPk(AcctInfoVO acctInfoVo) throws Exception {
        AcctInfo acctInfo = new AcctInfo();
        beanCopy(acctInfoVo, acctInfo);
        return acctInfoDao.updateByPk(acctInfo);
    }

    /**
     * 根据主键查询详情
     *
     * @param inAcctInfoVo
     * @return
     */
    @Override
    public AcctInfoVO queryByPk(AcctInfoVO inAcctInfoVo) throws Exception {
        AcctInfo queryAcctInfo = new AcctInfo();
        beanCopy(inAcctInfoVo, queryAcctInfo);
        AcctInfo queryRslAcctInfo = acctInfoDao.queryByPk(queryAcctInfo);
        return beanCopy(queryRslAcctInfo, new AcctInfoVO());
    }

    @Override
    public List<AcctInfoVO> queryCertCodeAndCertTypeAndPrdId(AcctInfoVO acctInfoVO) throws Exception {
        AcctInfo info = new AcctInfo();
        beanCopy(acctInfoVO,info);
        List<AcctInfo> acctInfos = acctInfoDao.queryCertCodeAndCertTypeAndPrdId(info);
        List<AcctInfoVO> list = new ArrayList<>();
        acctInfos.forEach(item->{
            AcctInfoVO vo = new AcctInfoVO();
            beanCopy(item,vo);
            list.add(vo);
        });
        return list;
    }

    public List<AcctInfoVO> queryGJJList() throws Exception {
        return (List<AcctInfoVO>) beansCopy(acctInfoDao.queryGJJList(), AcctInfoVO.class);

    }


}
